﻿package mortal.game.view.guide.guideUse
{
    import com.gengine.global.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.utils.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.interfaces.*;

    public class GuideUseWinBase extends SmallWindow
    {
        private var _showTween:TweenMax;
        protected var _item:BaseItem;
        protected var _itemEffect:SWFPlayer;
        public var isNotUseNext:Boolean = false;
        private var _timerId:int;
        protected var _itemData:ItemData;
        protected var _isCountdown:Boolean;
        protected var _guideUseItemData:GuideUseItemData;
        protected var _tmpHidePoint:Point;
        public static var isShowing:Boolean = false;

        public function GuideUseWinBase(param1:ILayer = null)
        {
            super(param1);
            this.layer = LayerManager.topLayer;
            return;
        }// end function

        protected function disposeTimer() : void
        {
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            return;
        }// end function

        public function hideForDrama(param1:Boolean = true) : void
        {
            if (param1)
            {
                if (this._tmpHidePoint == null)
                {
                    this._tmpHidePoint = new Point();
                }
                this._tmpHidePoint.x = this.x;
                this._tmpHidePoint.y = this.y;
                this.x = 4000;
            }
            else if (this._tmpHidePoint != null)
            {
                this.x = this._tmpHidePoint.x;
                this.y = this._tmpHidePoint.y;
            }
            return;
        }// end function

        protected function addTimer() : void
        {
            if (this._isCountdown)
            {
                this.disposeTimer();
                this._timerId = setTimeout(this.timerOut, 5000);
            }
            return;
        }// end function

        protected function timerOut() : void
        {
            return;
        }// end function

        public function get guideUseItemData() : GuideUseItemData
        {
            return this._guideUseItemData;
        }// end function

        public function set guideUseData(param1:GuideUseItemData) : void
        {
            this._guideUseItemData = param1;
            this._itemData = param1.itemData;
            this._item.itemData = param1.itemData;
            this._isCountdown = param1.isCountdown;
            this._item.updateStrengLevel();
            if (this._itemData.itemInfo.color >= 0 && this._itemData.itemInfo.color <= 4)
            {
                this._itemEffect.load("guideUseItemEffect_" + this._itemData.itemInfo.color + ".swf", ModelType.NormalSwf, null);
            }
            else
            {
                this._itemEffect.load("guideUseItemEffect_0.swf", ModelType.NormalSwf, null);
            }
            this.updateData();
            this.addTimer();
            return;
        }// end function

        protected function updateData() : void
        {
            return;
        }// end function

        public function get itemData() : ItemData
        {
            if (this._item == null)
            {
                return null;
            }
            return this._item.itemData;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.scaleX = 0.5;
            this.scaleY = 0.5;
            if (this._showTween != null)
            {
                this._showTween.kill();
            }
            this._showTween = TweenMax.to(this, 0.5, {scaleX:1, scaleY:1, ease:Back.easeOut});
            isShowing = true;
            return;
        }// end function

        protected function updateWinPlace() : void
        {
            var _loc_1:* = Global.stage.stageWidth;
            var _loc_2:* = Global.stage.stageHeight;
            var _loc_3:* = _loc_1 / 2 + 432;
            var _loc_4:* = _loc_2 / 2 + 96;
            if (_loc_3 + this.width + 20 > _loc_1)
            {
                _loc_3 = _loc_1 - this.width - 20;
            }
            if (_loc_4 + this.height + 25 > _loc_2)
            {
                _loc_4 = _loc_2 - this.height - 25;
            }
            this.move(_loc_3, _loc_4);
            return;
        }// end function

        override public function hide() : void
        {
            var _loc_1:Boolean = false;
            isShowing = false;
            if (this._item != null && this._item.itemData != null)
            {
                _loc_1 = this._item.itemData.extData == UpdateCode.EUpdateCodeTaskAndGuide;
            }
            super.hide();
            this.scaleX = 1;
            this.scaleY = 1;
            if (this._showTween != null)
            {
                this._showTween.kill();
                this._showTween = null;
            }
            if (!this.isNotUseNext)
            {
                GameController.npc.lastOpTime = getTimer();
                GameController.guide.useNextItem();
            }
            return;
        }// end function

        override protected function addWindowLine() : void
        {
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 20 - _contentTopOf3DSprite.x + _contentX;
                _closeBtn.y = 5 - _contentTopOf3DSprite.y + _contentY;
            }
            return;
        }// end function

        override protected function setWindowBgName() : void
        {
            _windowBgName = ImagesConst.SmallWinBg;
            return;
        }// end function

        protected function updatePos() : void
        {
            if (_windowBg)
            {
                _windowBg.setSize(291, this.height);
                _windowBg.x = 0;
                _windowBg.y = -40;
            }
            if (this._item)
            {
                this._item.x = (this.width - this._item.width) * 0.5;
            }
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            this.updatePos();
            this.updateWinPlace();
            updateWindowCenterSize();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._item.dispose(param1);
            this._item = null;
            this._itemEffect.dispose(param1);
            this._itemEffect = null;
            this._guideUseItemData = null;
            this._itemData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            blurTop = 0;
            blurBottom = 0;
            blurLeft = 0;
            blurRight = 0;
            this.setSize(291, 281);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.x = 110;
            this._item.y = -40;
            this._item.isShowLock = true;
            this._item.isShowArroundEffect = false;
            this._item.setItemStyle(ItemStyleConst.Big, "", 6, 6);
            addChild(this._item);
            this._itemEffect = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
            this._itemEffect.move(this._item.x + 34, this._item.y + 36);
            this.addChild(this._itemEffect);
            return;
        }// end function

    }
}
